home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / FileRequester.c < prev    next >
C/C++ Source or Header  |  2000-05-09  |  7KB  |  179 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/FileRequester.c,v 41.11 2000/05/09 20:33:36 mlemos Exp $
  3.  *
  4.  * FileRequester.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: FileRequester.c,v $
  12.  * Revision 41.11  2000/05/09 20:33:36  mlemos
  13.  * Bumped to revision 41.11
  14.  *
  15.  * Revision 1.2  2000/05/09 19:58:54  mlemos
  16.  * Merged with the branch Manuel_Lemos_fixes.
  17.  *
  18.  * Revision 1.1.2.1  1998/02/28 17:45:16  mlemos
  19.  * Ian sources
  20.  *
  21.  *
  22.  */
  23.  
  24. /* Execute me to compile with DICE V3.0.
  25. dcc FileRequester.c -proto -mi -ms -mRR -3.0 -lbgui
  26. quit
  27. */
  28.  
  29. #include "DemoCode.h"
  30.  
  31. #include <libraries/asl.h>
  32. #include <proto/utility.h>
  33.  
  34. /*
  35. **      Bulk GetAttr(). This really belongs in amiga.lib... I think.
  36. **/
  37. ULONG GetAttrs( Object *obj, ULONG tag1, ... )
  38. {
  39.         struct TagItem          *tstate = ( struct TagItem * )&tag1, *tag;
  40.         ULONG                    num = 0L;
  41.  
  42.         while ( tag = NextTagItem( &tstate ))
  43.                 num += GetAttr( tag->ti_Tag, obj, ( ULONG * )tag->ti_Data );
  44.  
  45.         return( num );
  46. }
  47.  
  48. /*
  49. **      Put up a simple requester.
  50. **/
  51. ULONG Req( UBYTE *gadgets, UBYTE *body, ... )
  52. {
  53.         struct bguiRequest      req = { NULL };
  54.  
  55.         req.br_GadgetFormat     = gadgets;
  56.         req.br_TextFormat       = body;
  57.         req.br_Flags            = BREQF_AUTO_ASPECT;
  58.         req.br_Underscore       = '_';
  59.  
  60.         return( BGUI_RequestA( NULL, &req, ( ULONG * )( &body + 1 )));
  61. }
  62.  
  63. VOID StartDemo( void )
  64. {
  65.         Object          *filereq;
  66.         ULONG            rc, dr, fl, pt, pa, l, t, w, h;
  67.  
  68.         /*
  69.         **      Present a simple requester.
  70.         **
  71.         **      NOTE: For some reason the size of the requester is not
  72.         **            saved when RTPatch (from reqtools) is active. When
  73.         **            I have some time left I'll take a look and try to
  74.         **            find out why.
  75.         **/
  76.         if ( ! Req( "_Continue|_Go Away!", ISEQ_C "This demo shows you how to use the BGUI\n"
  77.                                            "BOOPSI ASL interface. It pops a simple Load requester\n"
  78.                                            "and let's you play with it. After this the requester\n"
  79.                                            "type is changed into a Save requester. Ofcourse the\n"
  80.                                            "current path, requester size and position etc. is saved\n"
  81.                                            "while the object remains valid." ))
  82.                 return;
  83.         /*
  84.         **      Create a filerequester object.
  85.         **/
  86.         filereq = FileReqObject, ASLFR_DoPatterns, TRUE, EndObject;
  87.  
  88.         /*
  89.         **      Object OK?
  90.         **/
  91.         if ( filereq ) {
  92.                 /*
  93.                 **      Pop the requester.
  94.                 **/
  95.                 if ( ! ( rc = DoRequest( filereq ))) {
  96.                         /*
  97.                         **      Obtain attribute values.
  98.                         **/
  99.                         GetAttrs( filereq, FRQ_Drawer,          &dr,
  100.                                            FRQ_File,            &fl,
  101.                                            FRQ_Pattern,         &pt,
  102.                                            FRQ_Path,            &pa,
  103.                                            FRQ_Left,            &l,
  104.                                            FRQ_Top,             &t,
  105.                                            FRQ_Width,           &w,
  106.                                            FRQ_Height,          &h,
  107.                                            TAG_END );
  108.                         /*
  109.                         **      Dump 'm on the console.
  110.                         **/
  111.                         Tell( "Drawer                : %s\n"
  112.                               "File                  : %s\n"
  113.                               "Pattern               : %s\n"
  114.                               "Path                  : %s\n"
  115.                               "Left,Top,Width,Height : %ld,%ld,%ld,%ld\n",
  116.                               dr, fl, pt, pa, l, t, w, h );
  117.                 } else if ( rc == FRQ_CANCEL )
  118.                         /*
  119.                         **      Requester canceled.
  120.                         **/
  121.                         Tell("Canceled\n" );
  122.                 else
  123.                         /*
  124.                         **      Error.
  125.                         **/
  126.                         Tell("Error %ld\n", rc );
  127.  
  128.                 /*
  129.                 **      Make it a save requester.
  130.                 **/
  131.                 if ( ! ( rc = SetAttrs( filereq, ASLFR_DoSaveMode, TRUE, TAG_END ))) {
  132.                         /*
  133.                         **      Pop the requester.
  134.                         **/
  135.                         if ( ! ( rc = DoRequest( filereq ))) {
  136.                                 /*
  137.                                 **      Obtain attribute values.
  138.                                 **/
  139.                                 GetAttrs( filereq, FRQ_Drawer,          &dr,
  140.                                                    FRQ_File,            &fl,
  141.                                                    FRQ_Pattern,         &pt,
  142.                                                    FRQ_Path,            &pa,
  143.                                                    FRQ_Left,            &l,
  144.                                                    FRQ_Top,             &t,
  145.                                                    FRQ_Width,           &w,
  146.                                                    FRQ_Height,          &h,
  147.                                                    TAG_END );
  148.                                 /*
  149.                                 **      Dump 'm to the console.
  150.                                 **/
  151.                                 Tell( "Drawer                : %s\n"
  152.                                       "File                  : %s\n"
  153.                                       "Pattern               : %s\n"
  154.                                       "Path                  : %s\n"
  155.                                       "Left,Top,Width,Height : %ld,%ld,%ld,%ld\n",
  156.                                       dr, fl, pt, pa, l, t, w, h );
  157.                         } else if ( rc == FRQ_CANCEL )
  158.                                 /*
  159.                                 **      Requester canceled.
  160.                                 **/
  161.                                 Tell("Canceled\n" );
  162.                         else
  163.                                 /*
  164.                                 **      Error.
  165.                                 **/
  166.                                 Tell("Error %ld\n", rc );
  167.                 } else
  168.                         /*
  169.                         **      Error with SetAttrs().
  170.                         **/
  171.                         Tell( "Error %ld\n", rc );
  172.                 /*
  173.                 **      Dump the filerequester object.
  174.                 **/
  175.                 DisposeObject( filereq);
  176.         } else
  177.                 Tell( "unable to create filerequester object.\n" );
  178. }
  179.